package tr.muyat.accelerometer.visualizer;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 
 * @author fxulusoy
 */
public class Server {

	private int port = 5555;
	private ServerSocket serverSocket;
	
	/**
	 * The constructor.
	 */
	public Server() {
		try {
			serverSocket = new ServerSocket(port);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		Server example = new Server();
		example.handleConnection();
	}

	public void handleConnection() {
		
		// Server listens requests from clients
		while (true) {
			try {
				System.out.println("Server waiting client requests...");
				Socket socket = serverSocket.accept();
				
				Chart chart = new Chart();
				new Thread (chart).start();
				new Thread (new ConnectionHandler(socket, chart)).start();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}

